The present invention relates to database accessing schemes and more particularly to methods for minimizing transactional incompatibilities for heavily concurrent data access among multiple users.
In highly concurrent systems it is often desirable to cache parts of the database in a middle tier. This capability is often provided by an object/relational (O/R) engine, which as well as caching, also provides an object model on top of the relational data model. As with any caching architecture, the goal is to off-load a central resource, and provide data access in the middle tier without overly burdening the database.
Such a caching mechanism works extremely well for data which is only being read. However, for data which is being modified (and in particular for cases of heavy concurrent modification) there is a potential for conflicts. That is, if there are multiple caches containing the same database information, and there are multiple concurrent updates to those cached copies, there is the potential for one update to be incompatible with another.
There are two basic approaches to solving this problem, which are referred to as pessimistic concurrency and optimistic concurrency. In pessimistic concurrency, it is assumed that conflicts may arise, and therefore it is never possible to have more than one modifiable copy of a given piece of data. Unfortunately, this requires that data access be serialized, and therefore this solution dramatically reduces the throughput of a heavily concurrent system.
The other approach is to use optimistic concurrency, which allows multiple modifiable copies to exist, and then requires that conflicting updates be detected subsequently. There are a number of existing solutions as to how to provide optimistic concurrency, which all use a variant of a xe2x80x9cversion number.xe2x80x9d That is, every time an update is made to the database, some kind of versioning information associated with that record is used to verify the consistency of the attempted update against the version already in the database. So, when a record is initially read from the database, the current values of the data record as well as its version number are stored. Subsequently, when it is time to update the record in the database, the update is only allowed to replace the current data in the database record if the version number has remained unchanged from when the record was initially read. Simultaneous with the database update, the version number associated with that record is also updated in the database. However, if the system detects that the version number has changed, the update is disallowed.
Reliance on version numbers, however, can result in xe2x80x9cfalsexe2x80x9d conflicts which occur because the version number is updated if any field in the record is updated, whereas it may be that only compatible subsets of fields were updated. In the case of a concurrent compatible update, there is in fact no conflict. However, a pure version number scheme will detect a conflict in this situation.
What is needed in the art is an intelligent scheme for concurrent optimistic access to a database which proactively eliminates false conflicts. The present invention satisfies this and other needs.
According to one aspect of the present, invention, a method is provided for minimizing conflicts in an optimistic concurrency database access scheme. The method includes the steps of permitting multiple users to access a data record concurrently, generating concurrent cache copies of the data record for each user who accesses the data record, each cache copy including an initial value for each of the data items which is correlated to the value in the data record, permitting each user to perform a transaction on their respective cache copies, tracking which data items were modified and whether they were read for each of the user transactions, and, for any transaction that includes modified data items, committing the transaction if no data item has been read, and committing the transaction if the data items that were read contain the same value as the initial value. In a more complex scheme, if desired, transactions can be committed only if the data items that were read satisfy the further criterion that said data records were read before any modification.
In a further aspect of the present invention, another method for minimizing conflicts in an optimistic concurrency database access scheme similarly permits multiple users to access a data record concurrently, generates concurrent cache copies of the data record for each user who accesses the data record, each cache copy including an initial value for each of the data items which is correlated to the value in the data record, and permits each user to perform a transaction on their respective cache copies. For each data item in the transaction, the method can use a first bit to track whether the data item was modified and a second bit to track the occurrence of a first prescribed operation relative to a second prescribed operation on the data item. For any transaction that includes modified data items, the transaction is committed in response to at least one predetermined criterion. The first and second prescribed operations can be, for example, a read operation and a modify operation. The prescribed criterion can be that the data items that were read contain the same value as the initial value, or that no data item has been read, or one or more other criteria, alone or in combination.
In yet a further aspect of the invention, the methodology is recited in terms of the steps that are required to perform as series of prescribed functions. That method minimizes conflicts in an optimistic concurrency database access scheme through a step for permitting multiple users to access a data record concurrently, a step for generating concurrent cache copies of the data record for each user who accesses the data record, each cache copy including an initial value for each of the data items which is correlated to the value in the data record, a step for permitting each user to perform a transaction on their respective cache copies, a step for tracking for each transaction which data items were modified and whether they were read, and, for any transaction that includes modified data items, a step for committing the transaction if no data item has been read, and a step for committing the transaction if the data items that were read contain the same value as the initial value.
These and other steps, features, aspects, and advantages of the invention will be apparent from the accompanying Drawings and Drawing Descriptions and the Detailed Description of Certain Preferred Embodiments.